using System.Drawing;
using System.IO;
using System.Windows.Forms;
using DrawTools.Editor;
using DrawTools.Editor.CanvasFigures;
using DrawTools.Properties;

namespace DrawTools.Tools
{
  /// <summary>
  ///   Rectangle tool
  /// </summary>
  public class RectangleTool : ObjectTool
  {
    protected EditorColorSettrings Settings { get; private set; }

    public RectangleTool(EditorColorSettrings settings)
    {
      Settings = settings;
      Cursor = new Cursor(new MemoryStream(Resources.Rectangle1));
    }

    public override void OnMouseDown(IDrawingCanvas canvas, MouseEventArgs e)
    {
      var rectangle = new CanvasRectangle(e.X, e.Y, 1, 1)
      {
        BorderColor = Settings.BorderColor
      };

      AddNewObject(canvas, rectangle);
    }

    public override void OnMouseMove(IDrawingCanvas canvas, MouseEventArgs e)
    {
      canvas.SetCursor(Cursor);

      if (e.Button == MouseButtons.Left)
      {
        var point = new Point(e.X, e.Y);
        canvas.GraphicsList[0].MoveHandleTo(point, 5, (Control.ModifierKeys & Keys.Shift) != 0);
        canvas.Refresh();
      }
    }
  }
}